package com.yootk.action;

import com.yootk.vo.Dept;
import com.yootk.vo.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 属性注入
 */
@RestController
@RequestMapping("/source/*")
public class SourceAction {

    @Value("${source.mysql}")
    private String mysql;
    @Value("${source.redis}")
    private String redis;
    @Value("${source.messages}")
    private List<String> messages;
    @Value("#{${source.infos}}")
    private Map<String, String> infos;

    @Autowired
    private Source source;

    @Autowired
    private Dept dept;

    @GetMapping(value = "show", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object show() {
        Map<String, Object> info = new HashMap<>();
        info.put("mysql", this.mysql);
        info.put("redis", this.redis);
        info.put("messages", this.messages);
        info.put("infos", this.infos);
        return info;
    }

    @GetMapping(value = "show2", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object show2() {
        return this.source;
    }

    @GetMapping(value = "get", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object get() {
        return this.dept;
    }
}
